package cn.huihe.demoai.controller;

import cn.huihe.demoai.common.Result;
import cn.huihe.demoai.common.SwaggerBearerAuth;
import cn.huihe.demoai.common.WebResponse;
import cn.huihe.demoai.vendor.qwen.ChatApi;
import cn.huihe.demoai.vendor.qwen.RequestQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@SwaggerBearerAuth
@RestController
@RequestMapping("/v1/chat")
@Tag(name = "Chat API")
public class ChatController {

    private final ChatApi chatApi;

    public ChatController(ChatApi chatApi) {
        this.chatApi = chatApi;
    }


    @GetMapping("/text")
    @Operation(
            summary = "text input",
            responses = {@ApiResponse(responseCode = "200")},
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "request query object")
    )
    public ResponseEntity<Result<String>> textChat(@RequestBody RequestQuery object) {
        return WebResponse.ok(chatApi.textInput(object.getPrompt()));
    }

    @GetMapping("/image")
    @Operation(
            summary = "image input",
            responses = {@ApiResponse(responseCode = "200")},
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "request query object")
    )
    public ResponseEntity<Result<List<Map<String, Object>>>> imageChat(@RequestBody RequestQuery object) {
        return WebResponse.ok(chatApi.imageInput(object.getImages(), object.getPrompt()));
    }

}
